package com.poetize.plus.entity.vo;

import com.poetize.plus.entity.po.WebInfo;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zuosy
 * @Date 2024/3/30 9:20
 **/
public record WebInfoVO(
        @Schema(description = "id")
        Long id,
        @Schema(description = "网站名称")
        String webName,
        @Schema(description = "网站信息")
        String webTitle,
        @Schema(description = "页脚")
        String footer,
        @Schema(description = "看板娘消息")
        String waifuJson
) {
    /**
     * 实体类转vo
     *
     * @param webInfo
     * @return
     */
    public static WebInfoVO convert(WebInfo webInfo) {
        return new WebInfoVO(
                webInfo.getId(),
                webInfo.getWebName(),
                webInfo.getWebTitle(),
                webInfo.getFooter(),
                webInfo.getWaifuJson());
    }

    /**
     * 实体类集合转vo集合
     *
     * @param webInfoList
     * @return
     */
    public static List<WebInfoVO> convert(List<WebInfo> webInfoList) {
        List<WebInfoVO> result = new ArrayList<>();
        webInfoList.forEach(webInfo -> {
            WebInfoVO vo = new WebInfoVO(
                    webInfo.getId(),
                    webInfo.getWebName(),
                    webInfo.getWebTitle(),
                    webInfo.getFooter(),
                    webInfo.getWaifuJson());
            result.add(vo);
        });
        return result;
    }
}
